//
//  AddToBuyView.m
//  7.13苏宁框架
//
//  Created by mini on 15/7/22.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "AddToBuyView.h"
#import "Common.h"
@implementation AddToBuyView

+(instancetype)createView
{
    return [[[NSBundle mainBundle]loadNibNamed:@"AddToBuyView" owner:nil options:nil]lastObject];
}

- (IBAction)CloseClick {
    if ([self.delegate respondsToSelector:@selector(closeDelegate)]) {
        [self.delegate closeDelegate];
    }
}
- (IBAction)ConfigClick {
     if ([_buyCount.text isEqualToString:@"1"])
     {
         _model.count = 1;
     }
    if ([self.delegate respondsToSelector:@selector(configDelegate)]) {
        [self.delegate configDelegate];
    }
}
-(void)setData:(XQModel*)model
{
    _model = model;
    [self.picture setImageWithURL:[NSURL URLWithString:_model.image[0]]];
    self.name.text = _model.name;
    self.price.text = _model.price;
}
- (IBAction)addBuyCount {
   int count  = [_buyCount.text intValue];
    count ++;
    NSString *str = [NSString stringWithFormat:@"%d",count];
    self.buyCount.text = str;
    _model.count = count;
}
- (IBAction)releaseBuyCount {
    //判断当前购买数量是否为1，为1不能再减
    if ([_buyCount.text isEqualToString:@"1"]) {
        self.releaseBuyCountView.userInteractionEnabled = NO;
       int count = [_buyCount.text intValue];
         _model.count = count;
    }
    else
    {
        int count = [_buyCount.text intValue];
        count--;
        _model.count = count;
        NSString *str = [NSString stringWithFormat:@"%d",count];
        self.buyCount.text = str;
    }
}
@end
